package com.tm;

import java.sql.*;

public class JDBCTest01 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tm", "root", "1111");

            Statement statement = connection.createStatement();

            String sql = "select * from stu";

            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()){
                int id = resultSet.getInt(1);
                String name = resultSet.getString(2);
                String sex = resultSet.getString(3);
                int cid = resultSet.getInt(4);
                System.out.println(id+" "+name+" "+sex+" "+cid);
            }

            resultSet.close();
            statement.close();
            connection.close();
            System.out.println("连接成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
